//
//  ViewController.m
//  GCD
//
//  Created by 宜必鑫科技 on 2017/11/6.
//  Copyright © 2017年 宜必鑫科技. All rights reserved.
//

#import "ViewController.h"
#import <Masonry.h>
#import <ReactiveObjC.h>
#import "PthreadController.h"
#import "NSThreadController.h"
#import "GCDController.h"
#import "NSOperationController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    
    /*
     iOS 多线程的方案
     */
    
    /*
     1.pthread
     01 特点：
     （1）一套通用的多线程API
     （2）适用于Unix\Linux\Windows等系统
     （3）跨平台\可移植
     （4）使用难度大
     
     02 使用语言：c语言
     03 使用频率：几乎不用
     04 线程生命周期：由程序员进行管理
     */
    
    /*
     2.NSThread
     01 特点：
     （1）使用更加面向对象
     （2）简单易用，可直接操作线程对象
     
     02 使用语言：OC语言
     03 使用频率：偶尔使用
     04 线程生命周期：由程序员进行管理
     */
    
    
    /*
     （3）GCD
     01 特点：
     （1）旨在替代NSThread等线程技术
     （2）充分利用设备的多核(自动)
     
     02 使用语言：OC语言
     03 使用频率：经常使用
     04 线程生命周期：自动管理
     */
    
    /*
     (4) NSOperation & NSOperationQueue
     01 特点：
     （1）基于GCD（底层是GCD）
     （2）比GCD多了一些更简单实用的功能
     （3）使用更加面向对象
     
     02 使用语言：OC语言
     03 使用频率：经常使用
     04 线程生命周期：自动管理
     */
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:button];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.top.mas_equalTo(100);
        make.height.mas_equalTo(50);
    }];
    [button setTitle:@"pthread" forState:0];
    button.backgroundColor = [UIColor darkGrayColor];
    [[button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        PthreadController *vc = [[PthreadController alloc]init];
        [self presentViewController:vc animated:YES completion:nil];
    }];
    
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:button1];
    button1.backgroundColor = [UIColor darkGrayColor];
    [button1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.top.equalTo(button.mas_bottom).offset(10);
        make.height.mas_equalTo(50);
    }];
    [button1 setTitle:@"NSThread" forState:0];
    [[button1 rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        NSThreadController *vc = [[NSThreadController alloc]init];
        [self presentViewController:vc animated:YES completion:nil];
    }];
    
    
    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:button2];
    button2.backgroundColor = [UIColor darkGrayColor];
    [button2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.top.equalTo(button1.mas_bottom).offset(10);
        make.height.mas_equalTo(50);
    }];
    [button2 setTitle:@"GCD" forState:0];
    [[button2 rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        GCDController *vc = [[GCDController alloc]init];
        [self presentViewController:vc animated:YES completion:nil];
    }];
    
    UIButton *button3 = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:button3];
    button3.backgroundColor = [UIColor darkGrayColor];
    [button3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.top.equalTo(button2.mas_bottom).offset(10);
        make.height.mas_equalTo(50);
    }];
    [button3 setTitle:@"NSOperation" forState:0];
    [[button3 rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        NSOperationController *vc = [[NSOperationController alloc]init];
        [self presentViewController:vc animated:YES completion:nil];
    }];
}




















@end
